#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
struct infer{
    string s;
    int sj, ks;
};
infer a[1100];
void solve()
{
    ll n;
    map<int, pair<string, int>> mp;
    cin >> n;
    for (ll i = 1; i <= n;i++)
    {
        string q;
        int w, e;
        cin >> q >> w >> e;
        mp[w] = {q, e};
    }
    ll t;
    cin >> t;
    while(t--)
    {
        ll x;
        cin >> x;
        cout << mp[x].first << " "<< mp[x].second << endl;
    }
}
int main()
{
    int t = 1;
   // cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
